package com.gmq.chapter01.interrupt;

/**
 * Created by gmq on 2017/08/09.
 *
 * @version 1.0
 * @since 2017/08/09 14:29
 */
public class MyThread02 extends Thread {

    @Override
    public void run() {
        super.run();

        try {

            for (int i = 0; i < 500000; i++) {
                if (this.interrupted()) {
                    System.out.println("已经是停止状态了！我要退出了！");
//                break;
                    throw new InterruptedException();
                }
                System.out.println("i=" + (i + 1));
            }
//        System.out.println("我被输出，如果此代码是for又继续运行，线程并未停止！");
            System.out.println(" 我在for下面 ");
        } catch (InterruptedException e) {
            System.out.println("run catch");
            e.printStackTrace();
        }
    }
}


